<template>
	<view class="ewm">
		<image class="bg" mode="widthFix" src="https://video.file.zhuochengyun.com/2024/02/2024021914114913034.png">
		</image>
		<image class="ewmimages" :src="ewmimages"></image>
		<view class="btn" @click="save">保存二维码 去微信扫一扫进群</view>
	</view>
</template>

<script>
	import {
		apiEwm,
		logout
	} from '../../apirequest/api.js';
	export default {
		data() {
			return {
				ewmimages: ''
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData() {
				apiEwm().then(res => {
					if (res.code === 1) {
						this.ewmimages = res.data.ewmimages
					}
				})
			},
			save() {
				uni.navigateToMiniProgram({
					appId: 'wx2c348cf579062e56',
					path: 'packages/restaurant/restaurant/restaurant.html?poi_id_str=3B81ROEU-Pnia5JETx8PlgI&poi_id=916474302346103&spu_id=1259776176',
					envVersion: "release",
					success: res => {
						// 打开成功
						console.log("打开成功", res);
					},
					fail: err => {
						console.log(err);
					}
				})
				uni.downloadFile({
					url: this.ewmimages, //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							console.log('下载成功', res);
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success(result) {
									uni.showToast({
										title: '已保存至相册'
									})
									console.log(res);
								},
								fail(err) {
									uni.showToast({
										title: '存至失败',
										icon: 'none'
									})
								}
							})
						}
					}
				});

			}
		}
	}
</script>

<style scoped lang="scss">
	.ewm {
		width: 100vw;
		min-height: 100vh;
		display: flex;
		background-color: #ee523b;
		position: relative;

		.bg {
			width: 100%;
		}

		.btn {
			width: 550rpx;
			height: 70rpx;
			background-color: #ee712e;
			color: #fff;
			line-height: 70rpx;
			border-radius: 35rpx;
			text-align: center;
			font-weight: bold;
			position: absolute;
			left: 50%;
			bottom: 100rpx;
			transform: translate(-50%, 0);
			font-size: 28rpx;
		}

		.ewmimages {
			width: 400rpx;
			height: 400rpx;
			position: absolute;
			left: 50%;
			bottom: 220rpx;
			transform: translate(-50%, 0);
		}
	}
</style>